﻿namespace AppblockConfig.Test
{
   using System;

   using AppBlock.Config;

   using Microsoft.VisualStudio.TestTools.UnitTesting;

   [TestClass] public class SettingsTest
   {
      [TestMethod]
      public void Settings()
      {
         var settings = new SettingsManager();
         var item = Entity.Factory(Guid.NewGuid(), "demoTest");

         settings.Set("value1", "module1", "key1", "key2");
         settings.Set("value2", "module2", "group1", "key3", "key4");
         settings.Set(item, "group1", "Entity1");

         var itemrecovered = settings.Get<Entity>("group1", "Entity1");
         Assert.AreEqual(item.Id, itemrecovered.Id);
         Assert.AreEqual(item.Name, itemrecovered.Name);
         Assert.AreEqual("value1", settings.Get<string>("module1", "key1", "key2"));
         Assert.AreEqual("value2", settings.Get<string>("group1", "module2", "key3", "key4"));
         Assert.AreEqual("", settings.Get<string>("group1", "module2", "", "key0"));
      }
   }

   public class Entity
   {
      public Guid Id { get; set; }

      public string Name { get; set; }

      public static Entity Factory(Guid id, string name) { return new Entity { Name = name, Id = id }; }
   }
}